package Classes.GameViews.ViewPanels// ActionScript file
{
	import Classes.GameDatas.GD_Mission;
	import Classes.GameDatas.GD_Player;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.GU_dealPower;
	import Classes.GameUtils.StyleManager;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.staticinfo.Language;
	import Classes.staticinfo.StaticInfo;
	
	import UIComponents.IMission;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;

	public class VP_Mission extends ViewPanel
	{
		private static var _instance:VP_Mission;
		private var _interfaceUI:Sprite;
		public function VP_Mission():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("UIMission_v") as Class);
			this.addChild(this.interfaceUI);
			this.interfaceUI.x=105.55;
			this.interfaceUI.y=21.2;
			this.addListener();
			this.addObserveFunc(GD_Player.instance,StaticInfo.COMPLETE_MISSION,completeMissionFun,false);
			this.addObserveFunc(GD_Player.instance,StaticInfo.CAN_NOT_FINISH_MISSION,openErrorUIFun,false);
		}
		
		private function openErrorUIFun():void
		{
			VP_errorPanel.instance.setErrorMessage(Language.cantFishMiss);
			VP_errorPanel.instance.enterFrame();
			GU_Sound.instance.playCommSound("System_Prompt");
		}
		
		/**
		 * 完成任务 关闭任务面板 
		 */		
		private function completeMissionFun():void
		{
			this.close();
//			VP_beathartWindon.instance.openBeathartWin();
			//暂时弹字体以后要用上面的那个类 ，此类需要修改  成为通用的类
//			VP_errorPanel.instance.setErrorMessage(Language.successMsg);
//			VP_errorPanel.instance.enterFrame();
//			GU_dealPower.instance.hanldFishMiss(this._mis.missionType);
		}
		
		private function addListener():void
		{
			this.addEventListener("close",closeHandler);
		}
		
		private function closeHandler(e:Event):void
		{
			this.close();
			GU_dealPower.instance.hanldCloseMiss(_mis.missionType);
		}
		
		private var _mis:GD_Mission;
		public function setMission(mission:IMission):void
		{
			this._mis=mission as GD_Mission;
			if(this._mis.taskStyle==10)
			{
				return;
			}
			this.interfaceUI["setMission"](mission);
			this.openAt(VS_Main.instance,true);
//			this.toCenter();	
			this.scaleX		=	this.scaleY		=	1;
			var cx:Number	=	(ZombieTown.instance.sysStage.stageWidth-740)/2;
			var cy:Number	=	(ZombieTown.instance.sysStage.stageHeight-510)/2;
			this.scaleX=0.1;
			this.scaleY=0.1;
			TweenLite.to(this,0.5,{scaleX:1,scaleY:1,x:cx,y:cy});
		}

		/*getter & setter*/
		public static function get instance():VP_Mission
		{
			if(!_instance)_instance=new VP_Mission();
			return _instance;
		}

		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}


	}
}